{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import rope.base.project\n",
    "import rope.base.project\n",
    "import rope.base.libutils\n",
    "import rope.contrib.codeassist\n",
    "from rope.refactor.restructure import Restructure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'foo': (<rope.base.resources.File \"helpers/test2.py\" at 0x7fb68fe715d0>, 8), 'a_func': (<rope.base.resources.File \"helpers/test2.py\" at 0x7fb68fe715d0>, 1)}\n",
      "    return 2    a = 1\n",
      "    b = 2 * a\n",
      "    c = a * foo() + b * 3\n",
      "    print(b, c)\n",
      "\n",
      "\n",
      "def foo():\n"
     ]
    }
   ],
   "source": [
    "# I'll come back to this\n",
    "\n",
    "source_path = 'src/helpers/test2.py'\n",
    "source_file_contents = open(source_path).read()\n",
    "function_order = [\"foo\", \"a_func\"]\n",
    "\n",
    "project = rope.base.project.Project('src')\n",
    "resource = project.get_resource('helpers/test2.py')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "def a_func(...): ...\n",
      "    ... # 4 lines\n",
      "def foo(...): ...\n",
      "    ... # 1 lines\n"
     ]
    }
   ],
   "source": [
    "# Updating the function to fix the issue and retesting\n",
    "def summarize_python_code_fixed(code: str) -> None:\n",
    "    lines = code.split('\\n')\n",
    "    \n",
    "    in_function = False\n",
    "    line_count = 0\n",
    "\n",
    "    for line in lines:\n",
    "        stripped = line.strip()\n",
    "\n",
    "        if stripped.startswith(\"def \") or stripped.startswith(\"class \"):\n",
    "            if in_function:\n",
    "                print(f\"    ... # {line_count} lines\")\n",
    "            print(stripped.split('(')[0] + \"(...): ...\")\n",
    "            in_function = True\n",
    "            line_count = 0\n",
    "        elif stripped.startswith(\"#\") or stripped == \"\":\n",
    "            pass\n",
    "        else:\n",
    "            if in_function:\n",
    "                line_count += 1\n",
    "\n",
    "    if in_function:\n",
    "        print(f\"    ... # {line_count} lines\")\n",
    "\n",
    "sample_python_code = resource.read()\n",
    "summarize_python_code_fixed(sample_python_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Imports and constants defined\n",
    "\n",
    "def center(text: str) -> str: ...\n",
    "\n",
    "\n",
    "custom_config = ...\n",
    "\n",
    "\n",
    "def on_ticket(\n",
    "    title: str,\n",
    "    summary: str,\n",
    "    issue_number: int,\n",
    "    issue_url: str,\n",
    "    username: str,\n",
    "    repo_full_name: str,\n",
    "    repo_description: str,\n",
    "    installation_id: int,\n",
    "    comment_id: int = None,\n",
    "    edited: bool = False,\n",
    "    tracking_id: str | None = None,\n",
    "):\n",
    "    ...\n",
    "\n",
    "\n",
    "def review_code(\n",
    "    repo,\n",
    "    pr_changes,\n",
    "    issue_url,\n",
    "    username,\n",
    "    repo_description,\n",
    "    title,\n",
    "    summary,\n",
    "    replies_text,\n",
    "    tree,\n",
    "    lint_output,\n",
    "    plan,\n",
    "    chat_logger,\n",
    "    commit_history,\n",
    "    review_message,\n",
    "    edit_sweep_comment,\n",
    "    repo_full_name,\n",
    "    installation_id,\n",
    "):\n",
    "    ...\n",
    "\n",
    "def fetch_relevant_files(\n",
    "    cloned_repo,\n",
    "    title,\n",
    "    summary,\n",
    "    replies_text,\n",
    "    username,\n",
    "    metadata,\n",
    "    on_ticket_start_time,\n",
    "    tracking_id,\n",
    "    edit_sweep_comment,\n",
    "    is_paying_user,\n",
    "    is_consumer_tier,\n",
    "    issue_url,\n",
    "):\n",
    "    ..."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.10 ('sweepai-u_CIt3kb-py3.10')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "25d341f3248a096a89b9dbf6eec8e41f63aed02f6ba059df22a49224e3e8f1b0"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
